package cn.com.forever.array;

public class 二维数组中的查找 {
    public static void main(String[] args) {
        int[][] array = {{1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}};
        Find(1,array);
    }

    public static boolean Find(int target, int [][] array) {
        if(array == null) return false;
        int row = 0;
        int col = array[0].length-1;
        while(row < array.length && col >= 0){
            if(array[row][col] == target){
                return true;
            }
            else if(array[row][col] > target){
                col--;
            }
            else{
                row++;
            }
        }
        return false;
    }
}
